package com.inspur.dgov.bsp.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.inspur.dgov.bsp.user.entity.PubOrgan;
import com.inspur.dgov.bsp.user.entity.PubRegion;
import com.inspur.dgov.bsp.user.entity.PubUser;
import com.inspur.dgov.bsp.user.mapper.TreeMapper;
import com.inspur.dgov.bsp.user.service.TreeService;
import com.inspur.dgov.bsp.user.vo.OrganNode;
import com.inspur.dgov.common.tool.node.TreeNode;
import com.inspur.dgov.common.tool.node.TreeNodeUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 系统各种树服务实现类
 *
 * @Author chiyupei
 * @Date 19/9/24 上午10:29
 * @Version 1.0
 * @Description 系统各种树服务实现类
 */
@Slf4j
@Service
@AllArgsConstructor
public class TreeServiceImpl extends ServiceImpl<TreeMapper, TreeNode> implements TreeService {

    /**
     * 子级区划树
     * @param root
     * @return
     */
    @Override
    public List<OrganNode> regionTree(PubRegion root) {
        return TreeNodeUtil.merge(baseMapper.regionTree(root));
    }

    /**
     * 组织机构树
     * @param organ
     * @return
     */
    @Override
    public List<OrganNode> organTree(PubOrgan organ) {
        return TreeNodeUtil.merge(baseMapper.organTree(organ));
    }

    /**
     * 用户树
     * @param user
     * @return
     */
    @Override
    public List<TreeNode> userTree(PubUser user) {
        return TreeNodeUtil.merge(baseMapper.userTree(user));
    }
}
